package top.huntwolf.admin.pojo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import top.huntwolf.admin.common.enums.BookConditionEnum;
import top.huntwolf.admin.common.enums.EnumValue;

import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class BookReserve {

    private Integer ReserveId;

    private String isbn;

    private BookConditionEnum conditionEnum;

    private String discount;

    private int storage;

    private String realPrice;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonIgnore
    private Date createTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonIgnore
    private Date updateTime;

    @JsonIgnore
    private Integer storeId;

    public void setConditionEnum(Object condition){
        if (condition instanceof BookConditionEnum){
            conditionEnum = (BookConditionEnum) condition;
        }else{
            conditionEnum = EnumValue.valueOf(BookConditionEnum.class,condition);
        }
    }
}
